package com.darker.secking.utils;

import com.darker.secking.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MD5Util {
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }
    //固定盐

    private static final String salt="1a2b3c4d";

    //前端传过来的密码进行第一次加密
    public static String inputPassToFormPass(String inputPass) {
        String str =""+salt.charAt(0)+salt.charAt(2) + inputPass
                +salt.charAt(5) + salt.charAt(4);

        return md5(str);
    }
    //后端to数据库       密码再次加密传入数据库
    public static String formPassToDBPass(String formPass,String salt){
        String str = ""+salt.charAt(0)+salt.charAt(2) + formPass
                +salt.charAt(5) + salt.charAt(4);

        return md5(str);
    }

    public static String inputPassToDbPass(String inputPass,String salt){
        String formPass = inputPassToFormPass(inputPass);
        String dbPass = formPassToDBPass(formPass, salt);
        return dbPass;
    }

    public static void main(String[] args) {
        System.out.println(inputPassToFormPass("123456"));
        System.out.println(formPassToDBPass(("d3b1294a61a07da9b49b6e22b2cbd7f9"),"1a2b3c4d"));
        System.out.println(inputPassToDbPass("123456", "1a2b3c4d"));
        System.out.println(formPassToDBPass(("d3b1294a61a07da9b49b6e22b2cbd7f9"),"1a2b3c4d").equals("b7797cce01b4b131b433b6acf4add449"));
//        d3b1294a61a07da9b49b6e22b2cbd7f9


    }
}
